<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<link href="${basePath}/static/css/Pigeonhole/Pigeonhole_list.css" rel="stylesheet" type="text/css">
<link href="${basePath}/static/css/list.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="${basePath}/static/publics/assets/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath}/static/js/util.js"></script>
<div class="list_NR">
	<div class="loc">
	    <h3>新增病案</h3>
	    <!-- <ul class="loc_loc">病案归档 > 数据补录
	    </ul> -->
	</div>
	<div class="list_con_table">
            <div class="search_table">
               <ul class="clearfix" style="margin-bottom:0;">
               	<form method="post" style="height:144px;" id="addForm" action="${basePath}/medrecord/newRedrecord">
                   <li class="Label_1" style="color: red;">姓名：</li>
                   <li class="Label_2"><input class="input_box" type="text"  name='name' id='name' value='' title=""/></li>
                   <li class="Label_1">身份证号：</li>
                   <li class="Label_2">
                   <input type="hidden" name="identityDocumentTypeId" value="1"/>
                   <input class="input_box" type="text"  name='idNumber' id='idNumber' value=''/></li>
                    <li class="Label_1">性别：&nbsp;</li>
                   <li class="Label_2">
                   <select name="sexId" id="sexId" style="width:95%;height:30px">
                   		<option value="">请选择性别</option>
                   		<c:forEach items="${basicInfo['sexes']}" var="sex">
                   			<option value="${sex.id}">${sex.name}</option>
                   		</c:forEach>
                   	</select>
                   	<input type="hidden" name="sexName" id="sexName">
                   	
                   <li class="Label_1">出生日期：&nbsp;</li>
                   <li class="Label_2"><input class="input_box" type="text"  onFocus="WdatePicker()"  name='birthday' id='' value='' /></li>
                   <li class="Label_1" style="color: red;">ID号：</li>
                    <li class="Label_2"><input class="input_box" type="text"  name="mrId" id='mrId' value='' title=""/></li>
                  
                   <li class="Label_1">病案号：</li>
                   <li class="Label_2"><input class="input_box" type="text"  name='onlyId' id='onlyId' value='' /></li>
                  
                   <li class="Label_1" >入院日期：</li>
                   <li class="Label_2"><input class="input_box" type="text" name='inHospitalDate' id='inHospitalDate' value='' 
                   		onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/></li>
                  
                   <li class="Label_1">入院科室：</li>
                   <li class="Label_2">
                   	<select name="inDeptId" id="inDeptId" style="width:95%;height:30px" value=''>
                   		<option value="">请选择科室：</option>
                   		<c:forEach items="${offices}" var="office">
                   			<option value="${office.id}">${office.name}</option>
                   		</c:forEach>
                   	</select>
                   </li>
                   <input type="hidden" name="inDeptName" id="inDeptName">
                   
                   <li class="Label_1" style="color:red">住院次数：</li>
                   <li class="Label_2"><input class="input_box" type="text"  name='inHospitalNumber' id='inHospitalNumber' value='' title=""/></li>
                   
                   <li class="Label_1" style="color: red;">出院日期：</li>
                   <li class="Label_2"><input class="input_box" type="text" name='outHospitalDate' id='outHospitalDate' value='' 
                   		onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" title="" /></li>
                  
                   <li class="Label_1">出院科室：</li>
                   <li class="Label_2">
                   	<select name="outDeptId" id="outDeptId" style="width:95%;height:30px"  value=''>
                   		<option value="">请选择科室：</option>
                   		<c:forEach items="${offices}" var="office">
                   			<option value="${office.id}">${office.name}</option>
                   		</c:forEach>
                   	</select>
                   </li>
                   <input type="hidden" name="outDeptName" id="outDeptName">
                   
                   <li class="Label_1" style="color: red;">离院方式：</li>
                   <li class="Label_2">
                   <select name="outHospitalTypeId" id="outHospitalTypeId" style="width:95%;height:30px" title="">
                   		<option value="">请选择离院方式</option>
                   		<c:forEach items="${basicInfo['outHospitalTypes']}" var="outHospitalType">
                   			<option value="${outHospitalType.id}">${outHospitalType.name}</option>
                   		</c:forEach>
                   	</select>
                   </li>
                   <input type="hidden" name="outHospitalTypeName" id="outHospitalTypeName">
                   
                   <li class="Label_5">
                       <a id="Add" onclick="addFormSubmit()">新增</a>
                       
                   </li>
                   </form>
               </ul>
           </div> 
         
       </div>
       
</div>

<script type="text/javascript">

	$(function() {
		$("#sexId").change(function() {
			if ( $(this).val()!=null &&  $(this).val() != '') {
				var sexName = $(this).find("option:selected").text();
				$("#sexName").val(sexName);
				console.log($(this).find("option:selected").text());	
			} else {
				$("#sexName").val("");
			}
		});
		
		//入院科室
		$("#inDeptId").change(function() {
			if ($(this).val()!=null &&  $(this).val() != '') {
				var inDeptName = $(this).find("option:selected").text();
				$("#inDeptName").val(inDeptName);
				console.log($("#inDeptName").val());
			} else {
				$("#inDeptName").val("");
				console.log($("#inDeptName").val());
			}
		});
		
		//出院科室
		$("#outDeptId").change(function() {
			if ($(this).val()!=null &&  $(this).val() != '') {
				var outDeptName = $(this).find("option:selected").text();
				$("#outDeptName").val(outDeptName);
				console.log($("#outDeptName").val());
			} else {
				$("#outDeptName").val("");
				console.log($("#outDeptName").val());
			}
			
		});
		
		//离院方式
		$("#outHospitalTypeId").change(function() {
			if ($(this).val()!=null &&  $(this).val() != '') {
				var outHospitalTypeName = $(this).find("option:selected").text();
				$("#outHospitalTypeName").val(outHospitalTypeName);
				console.log($("#outHospitalTypeName").val());
			} else {
				$("#outHospitalTypeName").val("");
				console.log($("#outHospitalTypeName").val());
			}
			
			
		});
		
		
		
		
	});

	function addFormSubmit(){
		console.log(111);
		
		$("input,select").focus(function() {
				$("[title='']").each(function() {
					$("[title='']").removeClass("input_change");
	
				});
		});
		
		var num = 0;//变量为1时 数据为空
		var notNull = false;//变量为true时提交数据
		
		$("[title='']").each(function() { //遍历元素对象   
			if ($(this).val() == "") { //判断元素对象的value值  
				$(this).addClass("input_change"); //添加css样式  
				num = 1;
			} else {
				notNull = true;
			}
		});
		
		if (num == 1) {
			layer.alert("必选项不能为空!",{icon:7});
			//alert("必选项不能为空!");
			notNull = false;
			return;
		}
		
		if(notNull==true){
		 	var name=document.getElementById("name").value;
		 	if(name.length>50){
		 		layer.alert("姓名格式不正确或超出长度!",{icon:7});
		 		//alert("姓名格式不正确或超出长度");
		 		$("#name").addClass("input_change");
		 		$("#name").focus(function(){
					$(this).removeClass("input_change");
				});
		 		return;
		 	}
		 	
		 	var idNumber=$("#idNumber").val();
		 	
		 	if(idNumber!=null && idNumber!='') {
		 		var flag=validateIdCard(idNumber);
			 	if(flag==false){
			 		$("#idNumber").addClass("input_change");
			 		$("#idNumber").focus(function(){
						$(this).removeClass("input_change");
					});
			 		return;
			 	}	
		 	}
		 	
		 	var loadingIndex = null;
		 	var url = "${basePath}/medrecord/newRedrecord";
		 	var dataform = $("#addForm").serialize();
		 	
		 						//ajax 
		 			layer.confirm("您确定新增病案吗?",{
          			 	 btn : [ '确定', '取消' ]//按钮
      				 }, function(index) {
      					layer.close(index);
		 						$.ajax({
                                         type:"post",
                                         url:url,
                                         dataType:"json",
                                         data:dataform,
                                         beforeSend:function(){
                                             loadingIndex = layer.load(1, {
                                                  shade: [0.1,'#fff'] //0.1透明度的白色背景
                                    	   });
                                	   },
                                         success:function(result){
                                        	 layer.close(loadingIndex);
                                              if (result.success){
                                                     alert(result.msg);
                                                     window.location.reload();
                                              } else {
                                                     alert(result.msg);
                                              }
                                         },
                                         error:function(XMLHttpRequest, textStatus, errorThrown) {
                                        	 layer.close(loadingIndex);
                                        	 alert("系统异常请联系管理员!");
                                         }  //error end 
                                        
                                  }); //ajax 结束
      				});
		 	
		 	
		//$("#addForm").submit();
	}
}
	
	
</script>




